<!-- Horizontal Form -->
 <div class="box box-info" id="pwdEditId">
      <div class="box-header with-border">
        <h3 class="box-title">修改密码</h3>
      </div>
      <!-- /.box-header -->
      <!-- form start -->
      <form class="form-horizontal">
        <div class="box-body">
          <div class="form-group">
            <label for="pwdId" class="col-sm-2 control-label">请输入原密码</label>
            <div class="col-sm-8">
              <input type="password" class="form-control" name="password" id="pwdId" placeholder="原密码">
            </div>
          </div>
          <div class="form-group">
            <label for="newPwdId" class="col-sm-2 control-label">请输入新密码</label>

            <div class="col-sm-8">
              <input type="password" class="form-control" name="newPwd" id="newPwdId" placeholder="新密码">
            </div>
          </div>
          <div class="form-group">
            <label for="cfgPwdId" class="col-sm-2 control-label">再次输入新密码进行确认</label>

            <div class="col-sm-8">
              <input type="password" class="form-control" name="cfgPwd" id="cfgPwdId" placeholder="密码确认">
            </div>
          </div>
         
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
          <button type="button" class="btn btn-default btn-cancel">退出</button>
          <button type="button" class="btn btn-info pull-right btn-save">修改</button>
        </div>
        <!-- /.box-footer -->
      </form>
    </div>
<script type="text/javascript">
   $(function(){
	   $(".box-footer")
	   .on("click",".btn-cancel",doCancel)
	   .on("click",".btn-save",doUpdateObject)
   });
   function doCancel(){
	   $("#mainContentId").html("");
   }
   function doUpdateObject(){
	   //1.获取用户提交数据
	   let usedPassword=$("#pwdId").val();
	   let newPassword=$("#newPwdId").val();
	   let againPassword=$("#cfgPwdId").val();
       //2.判断密码是否一致
       if(usedPassword==""){
         alert("必须输入原密码进行验证");return;
       }
       if(newPassword==""){
         alert("新密码不能为空");return;
       }
       if(newPassword.length<6){
         alert("密码不能小于6位");return;
       }
       if(newPassword!=againPassword){
            alert("两次输入密码不一致!");return;
       }
       //3.定义请求的url
       let url=`${baseUrl}/shoppingback/logininfo/${usedPassword}/${newPassword}`
	   //4.异步提交请求,执行更新操作
	   $.ajax({method:"put",url:url,crossDomain:true,xhrFields:{withCredentials:true},
         headers : {"Authorization": "Bearer " + window.localStorage.getItem("accessToken")},
         success(result){
		    if(result.success){
              if(result.status==401){
                alert(result.msg);
                return;
              }
              if(result.status==403){
                alert(result.msg);
                return;
              }
			 alert(result.msg);
			 localStorage.removeItem("accessToken");
             location.href="/login.html";
		    }else{
			 alert(result.msg);
		    }
	   }})
   }
</script>

    
    